MailHog Setting

  • STEPS

    1. Download MailHog

    1 https://github.com/mailhog/MailHog/releases/latest . For 64 bit windows look for MailHog_windows_amd64.exe and for 32 bit MailHog_windows_386.exe

    2 run the mailhog.exe

    3 Open http://localhost:8025/ in your browser.

    2. Update PHP configuration

    Open php.ini and search for mail function. Set SMTP=127.0.0.1 and smtp_port=1025 in php.ini file.

    
                        [mail function]
                        ; For Win32 only.
                        ; http://php.net/smtp
                        SMTP=127.0.0.1
                        ; http://php.net/smtp-port
                        smtp_port=1025
    
                        

    3. Update sendmail configuration

    Open senmail.ini from C:\xampp\sendmail\ directory and put smtp_server=127.0.0.1 and smtp_port=1025.

    
                        [sendmail]
                        smtp_server=127.0.0.1
                        smtp_port=1025
                        

    4. Sending email using php

    
                       
    
                      $to = 'recipients@email-address.com';
                      $subject = 'Hello from XAMPP!';
                      $message = 'This is a Mailhog test';
                      $headers = "From: your@email-address.com\r\n";
    
                      if (mail($to, $subject, $message, $headers)) {
                        echo "SUCCESS";
                      } else {
                        echo "ERROR";
                      }
    
                    
    Do followings before executing the php file
    1. mailhog.exe should be live
    2. Open http://localhost:8025/ in your browser.

    When you run the file you will receive an email in the MailHog inbox.